package com.dayu.rabbitmq.simple;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

import com.dayu.rabbitmq.util.MQUtil;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;

/**
 * @author dayu
 * @date 2019/02/19
 * @Describe 简单队列
 */
public class Send {

    private static String QUEUE_NAME = "test_queue_name";

    public static void main(String[] args) {

        try {
            // 获取一个连接
            Connection connection = MQUtil.getConnection();
            // 从连接中获取一个通道
            Channel channel = connection.createChannel();

            // channel.queueDeclare(queue, durable, exclusive, autoDelete, arguments);
            // 创建队列声明
            channel.queueDeclare(QUEUE_NAME, false, false, false, null);

            String msg = "hello world！！";
            channel.basicPublish("", QUEUE_NAME, null, msg.getBytes());

            System.out.println("---send message---");

            channel.close();
            connection.close();
        } catch (IOException | TimeoutException e) {
            e.printStackTrace();
        }

    }
}
